/*******************************************************************************
 * Copyright (c) 2005, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/**
 * 
 */
package us.gaaoc.framework.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;

import us.gaaoc.framework.model.CaseRecord;
import us.gaaoc.framework.model.CaseRecordStatus;

/**
 * 
 * @author hea
 * @date Apr 17, 2006
 * @version: GAJE 1.5
 * 
 */
public class CaseRecordStatusDAOHibernate
		extends
		GenericHibernateDAO<CaseRecordStatus, Integer, CaseRecordStatusDAOHibernate>
		implements CaseRecordStatusDAO {

	protected CaseRecordStatusDAOHibernate() {

	}

	public CaseRecordStatus findCaseRecordStatusByCode(int code) {
		Query q = this.getSession().createQuery("from CaseRecordStatus crs where crs.code = ? ");
        q.setInteger(0, code);
        return (CaseRecordStatus)q.uniqueResult();
	}
	
	/**
	 * Get a list of strings of descriptions of the case record statuses
	 * One use of this list is in the creation of UISelectItem uiItems to populate a list box.
	 * A user can then select a description for possible modification of the status of a case
	 * @return a list of descriptions
	 */
	public List<String> getCaseRecordStatusDescriptionList() {
		List<String> caseRecordStatusDescriptionList = new ArrayList<String>();
		String sql = "SELECT description FROM CaseRecordStatus";
		Query q = getSession().createQuery(sql);
		caseRecordStatusDescriptionList = (List<String>)q.list();
        return caseRecordStatusDescriptionList;
	}
	
	/**
	 * Given a description of the case record status get the code
	 * @param caseRecordStatusDescription
	 * @return caseRecordStatusCode
	 */
	public int findCaseRecordStatusCode(String caseRecordStatusDescription){
		Integer caseRecordStatusCode;
		String sql = "select code from CaseRecordStatus where description = ?";		
		Query q = getSession().createQuery(sql);
		q.setString(0, caseRecordStatusDescription);
		caseRecordStatusCode = (Integer)q.uniqueResult();		
		return caseRecordStatusCode.intValue();
	        
	}

}
